﻿
using HBase;
using Net.http;
using System.Collections.Generic;
namespace hCommand {
    [RoutePrefix("param")]
    public class ParamServe :BaseApiController {
        IWCSServer wcsServer = WMSDalFactray.getDal<IWCSServer>();
        [HttpGet, Route("updateCraneOverStop/{craneId}/{value}")]
        public bool UpdateCraneOverStop(int craneId ,int value) {
            wcsServer.update("crane" ,craneId ,"overStop" ,value);

            List<BParam> list = wcsServer.getParams();
            MyCache.addOver(list);
            return true;
        }
        [HttpGet, Route("GetCraneOverStop/{craneId}")]
        public BaseResult GetCraneOverStop(int craneId) {
            BParam param = MyCache.getValue<BParam>(craneId);
            return BaseResult.Ok(param.v);
        }
        [HttpGet, Route("updateParam/{driveType}/{driveId}/{key}/{value}")]
        public BaseResult updateParam(string driveType ,int driveId ,string key ,int value) {
            bool res = wcsServer.update(driveType ,driveId ,key ,value);
            List<BParam> list = wcsServer.getParams();
            MyCache.addOver(list);
            return BaseResult.Ok(res);
        }
        [HttpGet, Route("updateValue/{id}/{value}")]
        public BaseResult updateParam( int id,  int value) {
            bool res = wcsServer.update(id, value);
            List<BParam> list = wcsServer.getParams();
            MyCache.addOver(list);
            return BaseResult.Ok(res);
        }

        [HttpGet, Route("getParam/{craneId}")]
        public BaseResult getParam(int craneId) {
            BParam param = MyCache.getValue<BParam>(craneId);
            return BaseResult.Ok(param);
        }
        [HttpGet, Route("queryParams/{type}/{index}/{key}")]
        public BaseResult queryParams(string type,int index,string key) {

            List<BParam> ps = MyCache.getList<BParam>();
            List<BParam> res = new List<BParam>();
            foreach (BParam p in ps) {
                if (!string.IsNullOrWhiteSpace(type) && type != p.driveType) {
                    continue; 
                }
                if (!string.IsNullOrWhiteSpace(key) && key != p.keyCode) {
                    continue;
                }
                if (index != 0 && index != p.driveIndex) {
                    continue;
                }
                res.Add(p);
            }
            return BaseResult.Ok(res);
        }
        [HttpGet, Route("getParams")]
        public BaseResult getParams() {
            
            List<BParam> res = MyCache.getList<BParam>();
            return BaseResult.Ok(res);
        }
    }
}
